/**
 *********************************************************
 ** <h1>SFMLex - Simple and Fast Multimedia Library Extensions.</h1>
 ** SFMLex Copyright (C) 2008 Neil Johnson (neil@emailus.me.uk)
 **
 ** SFML - Simple and Fast Multimedia Library
 ** Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
 **
 ** This software is provided 'as-is', without any express or implied warranty.
 ** In no event will the authors be held liable for any damages arising from the use of this software.
 **
 ** Permission is granted to anyone to use this software for any purpose,
 ** including commercial applications, and to alter it and redistribute it freely,
 ** subject to the following restrictions:
 **
 ** 1. The origin of this software must not be misrepresented;
 **    you must not claim that you wrote the original software.
 **    If you use this software in a product, an acknowledgment
 **    in the product documentation would be appreciated but is not required.
 **
 ** 2. Altered source versions must be plainly marked as such,
 **    and must not be misrepresented as being the original software.
 **
 ** 3. This notice may not be removed or altered from any source distribution.
 **
 ************************************************************
 */
#ifndef SFX_C_RESOURCE_MGR_H
#define SFX_C_RESOURCE_MGR_H


#include <map>
#include <list>
#include "xmlParser.h"
#include "c_Resource.h"
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include "c_AnimSprite.h"
#include "e_ErrorCodes.h"

namespace sfx
{
   
   class c_ResourceMgr
   {
   public:
      c_ResourceMgr(void);
      c_ResourceMgr( std::string& ScriptName );
      
      virtual ~c_ResourceMgr(void);
      
      bool loadScript( const std::string& ScriptName );
      
      bool cacheGroup( const std::string& GroupName );
      bool purgeGroup( const std::string& GroupName );
      
      //Resoruce get functions
      sf::Image*       getImage( const std::string& ImageName );
      sf::Sprite*      createSprite( const std::string& SpriteName );
      bool             freeSprite( const std::string& SpriteName, sf::Sprite* Sprite );
      sf::SoundBuffer* getSoundBuffer( const std::string& Name );
      sf::Music*       getMusic( const std::string& Name );
      c_AnimSprite*    createAnimSprite( const std::string& AnimSpriteName );
      bool             freeAnimSprite( const std::string& AnimSpriteName, c_AnimSprite* AnimSprite );

   private:    
      
      void init( void );
      
      bool loadScript( const std::string& ScriptName, std::list<c_Resource*>& NewResources );

      c_Resource* createResource( XMLNode& ResourceNode );
      
      void deleteResources( void );
   
   private:
      //Unimplemented
      c_ResourceMgr( const c_ResourceMgr& );
      c_ResourceMgr operator=( const c_ResourceMgr& );

   private:

      std::multimap< std::string, c_Resource* > m_GroupMap; //Map Group Names to resource;
      
      std::map< std::string, c_Resource* > m_NameMap; //Map resoruce Names to resource;
      
      std::list<c_Resource*> m_Resources;

   };
   
}

#endif //SFX_C_RESOURCE_MGR_H
